Skip to content

test(amber): add unit test coverage for Schedule iterator semantics#4562

Open
aglinxinyuan wants to merge 1 commit intoapache:mainfrom
aglinxinyuan:xinyuan-test-schedule-spec
Open

test(amber): add unit test coverage for Schedule iterator semantics#4562
aglinxinyuan wants to merge 1 commit intoapache:mainfrom
aglinxinyuan:xinyuan-test-schedule-spec

Conversation

@aglinxinyuan
Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Add ScheduleSpec covering the iterator semantics of Schedule (amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/Schedule.scala):

  • getRegions flattens all level sets across the map
  • Iteration order follows ascending level keys, starting from the minimum
  • hasNext / next() semantics including empty schedule, exhaustion, and non-zero starting level keys
  • Gap-stop behavior on non-contiguous level keys

Any related issues, documentation, discussions?

Closes #4561

How was this PR tested?

sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.scheduling.ScheduleSpec" — 7/7 tests pass.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.7)

### What changes were proposed in this PR?

Add `ScheduleSpec` covering the iterator semantics of `Schedule`:

- `getRegions` flattens all level sets across the map
- Iteration order follows ascending level keys, starting from the minimum
- `hasNext` / `next()` semantics including empty schedule, exhaustion,
  and non-zero starting level keys
- Gap-stop behavior on non-contiguous level keys

### Any related issues, documentation, discussions?

Closes apache#4561

### How was this PR tested?

`sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.architecture.scheduling.ScheduleSpec"` — 7/7 tests pass.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.7)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment on lines +77 to +84
it should "stop iteration at the first gap in level keys" in {
val r0 = region(0, "a")
val rGapped = region(2, "b")
val schedule = Schedule(Map(0 -> Set(r0), 2 -> Set(rGapped)))

assert(schedule.next() == Set(r0))
assert(!schedule.hasNext)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just disallow gaps?

Copy link
Copy Markdown
Contributor Author

@aglinxinyuan aglinxinyuan Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Added the contiguity invariant to Schedule itself in #4444 (commit 9472125) — it now requires level keys to be exactly 0..N-1, so gaps are no longer permitted. This test will need to be removed (and replaced with a require rejection test) once #4444 lands. I will update this PR to drop the gap/non-zero tests and add a rejection test.

Comment on lines +86 to +95
it should "begin iteration from the minimum level when level keys do not start at zero" in {
val r3 = region(3, "a")
val r4 = region(4, "b")
val schedule = Schedule(Map(3 -> Set(r3), 4 -> Set(r4)))

assert(schedule.hasNext)
assert(schedule.next() == Set(r3))
assert(schedule.next() == Set(r4))
assert(!schedule.hasNext)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should disallow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same — non-zero starting keys are now rejected by the require added to Schedule in #4444. Will follow up here once that lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(amber): add unit test coverage for Schedule iterator semantics

2 participants